package com.lzx.applib.video;

import com.lzx.applib.utils.LogUtil;

/**
 * Created by Administrator on 2017/3/23.
 */

public interface IMediaListener {

    void onPrepared();

    boolean onInfo(int what, int extra);

    void onPlayingBufferCache(int percent);

    void onTotalCacheUpdate(long percent);

    boolean onPositionUpdate(long position);

    void onSeekBegin();

    void onSeekComplete();

    void onCompletion();

    void OnCompletionWithParam(int i);

    boolean onError(int what, int extra);

    void onNetworkKBSpeedUpdate(int speed);

    void onVideoBuffer(boolean buffering);

    void setAdapter(IMediaListener listener);

    class SimpleMediaListener implements IMediaListener {

        public static final String TAG = "SimpleMediaListener";

        protected IMediaListener adapter;

        public SimpleMediaListener(){}

        public void setAdapter(IMediaListener adapter) {
            this.adapter = adapter;
        }

        @Override
        public void onCompletion() {
            log(TAG, "onCompletion");
            if (adapter != null) {
                adapter.onCompletion();
            }
        }

        @Override
        public boolean onError(int what, int extra) {
            log(TAG, "onError() called with:", what, extra);
            if (adapter != null) {
                return adapter.onError(what, extra);
            }
            return false;
        }

        @Override
        public void onNetworkKBSpeedUpdate(int speed) {
            log(TAG, "onNetworkKBSpeedUpdate() called with:", speed);
            if (adapter != null) {
                adapter.onNetworkKBSpeedUpdate(speed);
            }
        }

        @Override
        public void onPrepared() {
            log(TAG, "onPrepared");
            if (adapter != null) {
                adapter.onPrepared();
            }
        }

        @Override
        public void onSeekBegin() {
            log(TAG, "onSeekBegin");
            if (adapter != null) {
                adapter.onSeekBegin();
            }
        }

        @Override
        public void onSeekComplete() {
            log(TAG, "onSeekComplete");
            if (adapter != null) {
                adapter.onSeekComplete();
            }
        }

        @Override
        public boolean onInfo(int what, int extra) {
            log(TAG, "onInfo() called with:", what, extra);
            if (adapter != null) {
                return adapter.onInfo(what, extra);
            }
            return false;
        }

        @Override
        public void onPlayingBufferCache(int percent) {
            log(TAG, "onPlayingBufferCache() called with:", percent);
            if (adapter != null) {
                adapter.onPlayingBufferCache(percent);
            }
        }

        @Override
        public void onTotalCacheUpdate(long percent) {
            log(TAG, "onTotalCacheUpdate() called with:", percent);
            if (adapter != null) {
                adapter.onTotalCacheUpdate(percent);
            }
        }

        public void onVideoBuffer(boolean buffering) {
            log(TAG, "onVideoBuffer() called with:", buffering);
            if (adapter != null) {
                adapter.onVideoBuffer(buffering);
            }
        }

        @Override
        public boolean onPositionUpdate(long position) {
            log(TAG, "onPositionUpdate() called with:", position);
            if (adapter != null) {
                return adapter.onPositionUpdate(position);
            }
            return false;
        }

        @Override
        public void OnCompletionWithParam(int i) {
            log(TAG, "OnCompletionWithParam() called with:", i);
            if (adapter != null) {
                adapter.onPositionUpdate(i);
            }
        }

        protected static void log(Object... objs) {
            if (true) LogUtil.d(objs);
        }
    }
}